package com.example.service1.provider.fallback;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
import com.example.service1.common.api.entity.ResponseResult;
import com.example.service1.common.api.entity.ServiceStateCode;
import com.example.service1.common.vo.TestVo;

import java.time.LocalDate;

public class Service1Fallback {

    public static ResponseResult<TestVo> noArgGetThrowable(Throwable t) {
        System.out.println("==========服务提供者=============");
        System.out.println(t.getMessage()+" "+t.getCause());
        System.out.println("noArgGet    服务降级");
        return ResponseResult.failure(ServiceStateCode.CURRENT_LIMITING);
    }

    public static ResponseResult<TestVo> noArgGetBlockException(BlockException t) {
        System.out.println("==========服务提供者=============");
        if(t instanceof FlowException){
            System.out.println("流量控制异常");
        }else if(t instanceof DegradeException){
            System.out.println("服务熔断异常");
        }else if(t instanceof AuthorityException){
            System.out.println("权限异常");
        }else if(t instanceof SystemBlockException){
            System.out.println("SystemBlockException异常");
        }else if(t instanceof ParamFlowException){
            System.out.println("ParamFlowException异常");
        }else{
            System.out.println("怎么进来的该异常处理的");
        }
        System.out.println(t.getMessage()+" "+t.getCause());
        System.out.println("noArgGet    服务降级");
        return ResponseResult.failure(ServiceStateCode.CURRENT_LIMITING);
    }

    public static ResponseResult<TestVo> pathArgGetThrowable(String name, LocalDate date, Throwable t){
        System.out.println("==========服务提供者=============");
        System.out.println(t.getMessage()+" "+t.getCause());
        System.out.println("pathArgGet    服务降级");
        return ResponseResult.failure(ServiceStateCode.CURRENT_LIMITING);
    }
}
